<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">点击打印时间</button>
    <script>
        const btn = document.getElementById("btn");
        btn.onclick = console.log(getDate(2));
        //获取时间戳
        function getDate(num = 0) {
            let time = Date.now() + num * 1000 * 60 * 24; //当前时间戳
            let day = Math.floor(time / (1000 * 60 * 60 * 24))
            let hours = Math.floor((time / (1000 * 60 * 60)) % 24)
            let minutes = Math.floor((time / (1000 * 60)) % 60)
            let seconds = Math.floor((time / 1000) % 60)
            return day + '天' + hours + '小时' + minutes + '分钟' + seconds + '秒'
        }


    </script>
</body>

</html>